﻿Namespace SchoolClick.Database.DAL

    Public Interface IProfesores
        ReadOnly Property IProfesores As IProfesores

        Function GetActivos() As IEnumerable(Of V_PROFESORES)
        Function GetDesactivados() As IEnumerable(Of V_PROFESORES)
        Function GetGradoP(Identificador As String) As IEnumerable(Of GET_GRADO_BY_P_DATATYPE)
        Function GetMateriaP(Identificador As String, Grado As Integer) As IEnumerable(Of GET_MATERIA_BY_GRADO_P_DATATYPE)
        Function GetActividadP(Identificador As String, Grado As Integer, Materia As Integer, Periodo As String) As IEnumerable(Of GET_ACTIVIDAD_BY_MATERIA_DATATYPE)
        Function GetNotasAlumnosWithByActividad(Id_sub As Integer) As IEnumerable(Of GET_NOTAS_ACTIVIDADES_DATATYPE)
        Sub SaveNotaAlumnoActividad(IDAlumno As String, ID_sub As Integer, Nota As Decimal)

        Sub Desactivar(profesor As String)
        Sub Reactivar(profesor As String)
        Sub CrearProfesor(profesor As InfoProfesor)
        Sub DefinirMateriaAImpartir(IDGrado As Integer, Profesor As String, Materia As Integer)

        Function GetActividadesByActMod(IDGrado As Integer, IDMateria As Integer, IDPeriodo As String, IDActividad As String) As IEnumerable(Of ACTIVIDADES_EVALUATIVAS_MOD_BYACT)
        Sub SaveActividadEvaluativaMod(IDGrado As Integer, IDMAteria As Integer, IDPeriodo As String, IDActividad As String, Nombre As String, Porcentaje As Integer)
        Sub EliminarActividadEvaluativaMod(IDActividad As Integer)
    End Interface

    Partial Public Class SchoolClickDAL
        Implements IProfesores

        Public ReadOnly Property IProfesores As IProfesores Implements IProfesores.IProfesores
            Get
                Return DirectCast(Me, IProfesores)
            End Get
        End Property

        Private Function GetActivos() As IEnumerable(Of V_PROFESORES) Implements IProfesores.GetActivos
            Dim cnn As New SchoolClickEntities
            Try
                Return cnn.V_PROFESORES.Where(Function(p) p.ACTIVADO = True).ToArray
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Function

        Private Sub Desactivar(profesor As String) Implements IProfesores.Desactivar
            Dim cnn As New SchoolClickEntities
            Try
                cnn.DESACTIVAR_PROFESOR(profesor, ConfigurationManager.AppSettings("Rol_ERA").ToSecureString.ToStringInseguro)
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Sub

        Private Sub CrearProfesor(profesor As InfoProfesor) Implements IProfesores.CrearProfesor
            Dim cnn As New SchoolClickEntities
            Try
                cnn.NEW_PROFESOR(profesor.ID_Usuario, profesor.Nombres, profesor.Apellidos, profesor.DUI, profesor.Telefono, profesor.CorreoE,
                                 ConfigurationManager.AppSettings("Rol_ERA").ToSecureString.ToStringInseguro)
            Catch ex As EntityCommandExecutionException
                Throw New EntityCommandExecutionException(ex.InnerException.Message, ex)
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Sub

        Private Function GetDesactivados() As IEnumerable(Of V_PROFESORES) Implements IProfesores.GetDesactivados
            Dim cnn As New SchoolClickEntities
            Try
                Return cnn.V_PROFESORES.Where(Function(p) p.ACTIVADO = False).ToArray
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Function

        Private Sub Reactivar(profesor As String) Implements IProfesores.Reactivar
            Dim cnn As New SchoolClickEntities
            Try
                cnn.REACTIVAR_PROFESOR(profesor, ConfigurationManager.AppSettings("Rol_ERA").ToSecureString.ToStringInseguro)
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Sub

        Private Sub DefinirMateriaAImpartir(IDGrado As Integer, Profesor As String, Materia As Integer) Implements IProfesores.DefinirMateriaAImpartir
            Dim cnn As New SchoolClickEntities
            Try
                cnn.SAVE_PROFESOR_IMPARTE_MATERIA_EN_GRADO(Materia, Profesor, IDGrado,
                                                           ConfigurationManager.AppSettings("Rol_ERA").ToSecureString.ToStringInseguro)
            Catch ex As EntityCommandExecutionException
                Throw New EntityCommandExecutionException(ex.InnerException.Message, ex)
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Sub

        Private Function GetGradoP(Identificador As String) As IEnumerable(Of GET_GRADO_BY_P_DATATYPE) Implements IProfesores.GetGradoP
            Try
                Using cnn As New SchoolClickEntities
                    Return cnn.GET_GRADO_BY_P(Identificador).ToArray()
                End Using
            Catch ex As Exception
                Throw New ApplicationException("No se pudo recuperar las Grados que imparte el profesor", ex)
            End Try

        End Function

        Public Function GetMateriaP(Identificador As String, Grado As Integer) As IEnumerable(Of GET_MATERIA_BY_GRADO_P_DATATYPE) Implements IProfesores.GetMateriaP
            Try
                Using cnn As New SchoolClickEntities
                    Return cnn.GET_MATERIA_BY_GRADO_P(Identificador, Grado).ToArray()
                End Using
            Catch ex As Exception
                Throw New ApplicationException("No se pudo recuperar las Grados que imparte el profesor", ex)
            End Try
        End Function

        Public Function GetActividadP(Identificador As String, Grado As Integer, Materia As Integer, Periodo As String) As IEnumerable(Of GET_ACTIVIDAD_BY_MATERIA_DATATYPE) Implements IProfesores.GetActividadP
            Try
                Using cnn As New SchoolClickEntities
                    Return cnn.GET_ACTIVIDAD_BY_MATERIA(Identificador, Grado, Materia, Periodo).ToArray()
                End Using
            Catch ex As Exception
                Throw New ApplicationException("No se pudo recuperar las Grados que imparte el profesor", ex)
            End Try
        End Function

        Private Function GetActividadesByActMod(IDGrado As Integer, IDMateria As Integer, IDPeriodo As String, IDActividad As String) As IEnumerable(Of ACTIVIDADES_EVALUATIVAS_MOD_BYACT) Implements IProfesores.GetActividadesByActMod
            Dim cnn As New SchoolClickEntities
            Try
                Return cnn.GET_ACTIVIDADES_EVALUATIVAS_MOD_BYACT(IDActividad, IDMateria, IDGrado, IDPeriodo).ToArray()
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Function

        Private Sub SaveActividadEvaluativaMod(IDGrado As Integer, IDMAteria As Integer, IDPeriodo As String, IDActividad As String, Nombre As String, Porcentaje As Integer) Implements IProfesores.SaveActividadEvaluativaMod
            Dim cnn As New SchoolClickEntities
            Try
                cnn.INS_ACTIVIDAD_EVALUATIVA_MODIFICABLE(IDGrado, IDMAteria, IDPeriodo, IDActividad, Nombre, Porcentaje,
                                                           ConfigurationManager.AppSettings("Rol_ERA").ToSecureString.ToStringInseguro)
            Catch ex As EntityCommandExecutionException
                Throw New EntityCommandExecutionException(ex.InnerException.Message, ex)
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Sub

        Private Sub EliminarActividadEvaluativaMod(IDActividad As Integer) Implements IProfesores.EliminarActividadEvaluativaMod
            Dim cnn As New SchoolClickEntities
            Try
                cnn.DEL_ACTIVIDAD_EVALUATIVA_MODIFICABLE(IDActividad,
                                                           ConfigurationManager.AppSettings("Rol_ERA").ToSecureString.ToStringInseguro)
            Catch ex As EntityCommandExecutionException
                Throw New EntityCommandExecutionException(ex.InnerException.Message, ex)
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Sub

        Private Function GetNotasAlumnosWithByActividad(Id_sub As Integer) As IEnumerable(Of GET_NOTAS_ACTIVIDADES_DATATYPE) Implements IProfesores.GetNotasAlumnosWithByActividad
            Dim cnn As New SchoolClickEntities
            Try
                Return cnn.GET_NOTAS_ACTIVIDADES(Id_sub).ToArray
            Catch ex As Exception
                Throw ex
            Finally
                cnn.Dispose()
            End Try
        End Function

        Public Sub SaveNotaAlumnoActividad(IDAlumno As String, ID_sub As Integer, Nota As Decimal) Implements IProfesores.SaveNotaAlumnoActividad

        End Sub
    End Class
End Namespace

